package com.bw.service;

import com.bw.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;


    /**
     * 转账
     * @param userIdA 转账人
     * @param userIdB 收款人
     * @param amount  转账金额
     * @return true 成功  false 失败
     */
    @Transactional
    @Override
    public boolean transfer(Integer userIdA, Integer userIdB, Integer amount) {

            // 扣减 A的钱
            userMapper.updateAmountById(userIdA, amount);

            // 记录A的转账记录
            // 给A 发短信  发邮件  通知
            // 模拟真实业务 出现bug
            int  i = 1/0;
            // 充值 B的钱
            userMapper.updateAmountById(userIdB, -amount);

        return true;
    }
}
